package work;

import org.picocontainer.DefaultPicoContainer;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.behaviors.Locking;
import org.picocontainer.behaviors.Caching;
import org.picocontainer.Parameter;
import org.picocontainer.parameters.ConstantParameter;
import org.picocontainer.parameters.ComponentParameter;

public class Configurator {
	private static Configurator me;
	private static MutablePicoContainer container;

	public Configurator() {
	}

	public static Configurator cfg() {
		synchronized(Configurator.class) {
			if(container == null) {
				container = new DefaultPicoContainer(new Locking().wrap(new Caching()));
				container.addComponent(Configurator.class);
				me = container.getComponent(Configurator.class);
			}
		}
		return me;
	}

	public <T> void register(java.lang.Class<T> key) {
		container.addComponent(key);
	}

	public <T> void register(java.lang.Class<T> key, Parameter... params) {
		container.addComponent(key, key, params);
	}

	public <T> void register(java.lang.Class<T> key, Object obj, Parameter... params) {
		container.addComponent(key, obj, params);
	}

	public <T> T get(java.lang.Class<T> key) {
		return (T)container.getComponent(key);
	}
}
